import Taro, { Component, Config } from '@tarojs/taro'
import { Provider } from '@tarojs/mobx'
import Index from './pages/index'
import getStore from './store'
import './app.scss'

// 如果需要在 h5 环境中开启 React Devtools
// 取消以下注释：
// if (process.env.NODE_ENV !== 'production' && process.env.TARO_ENV === 'h5')  {
//   require('nerv-devtools')
// }

let store = getStore()

class App extends Component {
  /**
   * 指定config的类型声明为: Taro.Config
   *
   * 由于 typescript 对于 object 类型推导只能推出 Key 的基本类型
   * 对于像 navigationBarTextStyle: 'black' 这样的推导出的类型是 string
   * 提示和声明 navigationBarTextStyle: 'black' | 'white' 类型冲突, 需要显示声明类型
   */
  config: Config = {
    tabBar: {
      custom: true,
      list: [
        {
          pagePath: 'pages/index/index',
          text: '首页',
          iconPath: './images/skin/default/index.png',
          selectedIconPath: './images/skin/skin_red/index_on.png'
        },
        {
          pagePath: 'pages/category/index',
          text: '分类',
          iconPath: './images/skin/default/find.png',
          selectedIconPath: './images/skin/skin_red/find_on.png'
        },
        {
          pagePath: 'pages/shopCart/index',
          text: '购物车',
          iconPath: './images/skin/default/cart.png',
          selectedIconPath: './images/skin/skin_red/cart_on.png'
        },
        {
          pagePath: 'pages/userCenter/index',
          text: '个人中心',
          iconPath: './images/skin/default/my.png',
          selectedIconPath: './images/skin/skin_red/my_on.png'
        }
      ]
    },
    pages: ['pages/index/index', 'pages/category/index', 'pages/shopCart/index', 'pages/userCenter/index'],
    subPackages: [
      {
        root: 'subPackages/swiperTest',
        pages: ['index']
      },
      {
        root: 'subPackages/animators',
        pages: ['mode/index']
      },
      {
        root: 'subPackages/webp',
        pages: ['index', 'webPage']
      },
      {
        root: 'subPackages/camera',
        pages: ['index']
      },
      {
        root: 'subPackages/tvshow',
        pages: ['index']
      }
    ],
    window: {
      navigationStyle: 'default',
      backgroundTextStyle: 'light',
      navigationBarBackgroundColor: '#fff',
      navigationBarTitleText: 'WeChat',
      navigationBarTextStyle: 'black',
      backgroundColor: '#ffffff'
    }
  }

  componentDidMount() {}

  componentDidShow() {}

  componentDidHide() {}

  componentDidCatchError() {}

  // 在 App 类中的 render() 函数没有实际作用
  // 请勿修改此函数
  render() {
    return (
      <Provider store={store}>
        <Index />
      </Provider>
    )
  }
}

Taro.render(<App />, document.getElementById('app'))
